package com.luke.quartz.task;


import com.luke.base.domain.LkEquipment;
import com.luke.base.domain.LkUser;
import com.luke.base.domain.RetrieveAlarm;
import com.luke.base.service.ILkEquipmentService;
import com.luke.base.service.ILkUserService;
import com.luke.base.service.IRetrieveAlarmService;
import com.luke.base.util.HttpStatusException;
import com.luke.base.util.JPushUtil;
import com.luke.base.util.LukeApiUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;


/**
 * 定时任务调度测试
 * 
 * @author luke
 */
@Component("lkTask")
public class LkTask
{
    @Autowired
    private IRetrieveAlarmService retrieveAlarmService;
    @Autowired
    private ILkEquipmentService equipmentService;
    @Autowired
    private ILkUserService userService;

    //获取报警信息
    public void retrieveAlarm() throws HttpStatusException {
        List<RetrieveAlarm> alarmList= LukeApiUtil.retrieveAlarm();
        System.err.println("-----查询报警信息-------------"+alarmList.size());
        for (RetrieveAlarm alarm : alarmList) {
            //存储报警信息
            retrieveAlarmService.insertRetrieveAlarm(alarm);
            //推送报警信息
            //查询设备所属用户
            LkEquipment equipment=equipmentService.selectLkEquipmentByNumber(alarm.getCar_id());
            if (equipment.getUserId()!=null) {
                JPushUtil.sendPush(equipment.getUserId()+"",alarm.getAlarmInfo());
                //查询有无第二驾驶员
                LkUser user=userService.selectLkUserByParentId(equipment.getUserId());
                if (user!=null) {
                    JPushUtil.sendPush(user.getUserId()+"",alarm.getAlarmInfo());
                }
            }
        }
    }
}
